﻿using System;
using System.Net.Sockets;
using System.Net;
using System.Text;

namespace ChatClient
{
	public class ChatClient
	{
		private string sClientName = string.Empty;
		private string sClientSession = string.Empty;
		private IPEndPoint ipep = null;
		Socket clientSocket = null;


		//listener - receive: event
		//open port - wait on port xx


		public ChatClient()
		{
			ipep = new IPEndPoint(IPAddress.Parse(ChatClientConfig.Server_IP), ChatClientConfig.Server_Port);
			clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
		}

		public void SendMessage(string sReceiver, string sContent, string sXMLSchemaMessage)
		{
			byte[] bytes = new byte[256];

			

			clientSocket.Send(Encoding.UTF8.GetBytes("Client: hello"));
		}

		public void ReceiveMessage(string sReceiver, string sContent, string sXMLSchemaMessage)
		{
			byte[] bytes = new byte[256];

			clientSocket.Connect(ipep);

			clientSocket.Send(Encoding.UTF8.GetBytes("Client: hello"));

			clientSocket.Receive(bytes);
			System.Console.WriteLine("Client Receive:" + Encoding.UTF8.GetString(bytes));

		}


		public bool Login()
		{
			bool bResult = false;
			//connect to server
			try
			{
				clientSocket.Connect(ipep);
				bResult = true;
			}
			catch(Exception e)
			{ 
				// Log

			}

			return bResult;
		}

		public bool Logout()
		{
			bool bResult = false;
			clientSocket.Close();

			return bResult;
		}


	}
}
